
package com.yimixian.app.adapter;

import com.umeng.analytics.MobclickAgent;
import com.yimixian.app.common.StatConstants;
import com.yimixian.app.fragment.OrderMvpFragment;
import com.yimixian.app.model.Order;
import com.yimixian.app.order.OrderDetailActivity;
import com.yimixian.app.order.OrderListItemView;

import android.app.Activity;
import android.content.Intent;
import android.os.Handler;
import android.view.View;
import android.view.ViewGroup;

public class OrdersListViewAdapter extends ArrayListAdapter<Order> {

    private Handler mHandler;
    public OrdersListViewAdapter(Activity content) {
        super(content);
    }
    public void setHandler(Handler mHandler){
        this.mHandler = mHandler;
    }
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        OrderListItemView itemView = (OrderListItemView) convertView;
        if (itemView == null) {
            itemView = new OrderListItemView(mContext, mHandler);
        }
        itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MobclickAgent.onEvent(mContext, StatConstants.RECENT_ORDER_ITEM_CLICK);
                Intent intent = new Intent(mContext, OrderDetailActivity.class);
                intent.putExtra(OrderDetailActivity.EXTRA_ORDER_ID, mList.get(position).id);
                intent.putExtra(OrderDetailActivity.EXTRA_ORDER_POSITION, position);
                mContext.startActivity(intent);
            }
        });
        itemView.bind(mList.get(position));
        return itemView;
    }

    @Override
    public boolean hasStableIds() {
        return true;
    }

    @Override
    public boolean areAllItemsEnabled() {
        return true;
    }

}
